/**
 * Created by fkjslee on 2018/3/15.
 */

var serverUrl = "http://118.24.119.103:8081";
// var serverUrl = "http://127.0.0.1:8081";
var http = "http://";

var tableParamToolbar = [{
    text: '添加',
    iconCls: 'icon-add',
    handler: function () {
        showDlgChoose();
    }
}, '-', {
    text: "删除所选",
    iconCls: 'icon-remove',
    handler: function() {
        var row = $("#tableParam").datagrid("getSelected");
        if(row) {
            var index = $("#tableParam").datagrid("getRowIndex", row);
            $("#tableParam").datagrid("deleteRow", index);
        } else {
            $.messager.show({
                title: "错误的删除",
                msg: "确认你先选中一行再删除",
                showType: "show"
            })
        }
    }
}, '-', {
    text: '全部清除',
    iconCls: 'icon-clear',
    handler: function() {
        var rows = $("#tableParam").datagrid('getRows');
        if (rows) for (var i = rows.length - 1; i >= 0; i--) {
            $("#tableParam").datagrid('deleteRow', i);
        }
    }
}];


var fileTool = [{
    text: "删除",
    iconCls: 'icon-remove',
    handler: function() {
        var rows = $("#download-files").datagrid("getSelections");
        if (rows.length === 0) {
            $.messager.alert("提示", "请选择要删除的行！", "info");
            return;
        } else {
            var jsonStr = JSON.stringify($("#download-files").datagrid("getSelections"));
            var formData = new FormData();
            formData.append("files", jsonStr);
            formData.append("userName", logAccount);
            $.ajax({
                url: http + window.location.host + '/removeFile',
                type: 'POST',
                data: formData,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function (data) {
                    fillFileState();
                    if (JSON.parse(data).code === "0") {
                        $.messager.show({
                            title: "提交结果",
                            msg: "提交成功，等候处理",
                            type: "show"
                        })
                    } else {
                        $.messager.alert("提交结果", "出现问题 返回结果 " + data, "error");
                    }
                },
                error: function (returndata) {
                    fillFileState();
                }
            });
        }
    }
}, '-', {
    text: '刷新',
    iconCls: 'icon-reload',
    handler: function() {
        fillFileState();
    }
}, '-', {
    text: '下载',
    iconCls: 'icon-save',
    handler: function () {
        var rows = $("#download-files").datagrid("getSelections");
        if (rows.length === 0) {
            $.messager.alert("提示", "请选择要下载的文件！", "info");
            return;
        }
        else if(rows.length > 1) {
            $.messager.alert("提示", "同时下载多个文件似乎会被浏览器当广告,请一个一个下载", "info");
            return;
        } else {
            var fileName = rows[0].thFileName;
            window.open(url + "/downloadResultFile" + "?userName=" + encodeURIComponent(logAccount) + "&fileName=" + encodeURIComponent(fileName));
        }
    }
}];

var stationTool = [{
    text: '刷新',
    iconCls: 'icon-reload',
    handler: function() {
        fillStationState();
    }
}];

